#pragma once

#include <list>

#define LOCK
#define UNLOCK
#define UNLOCK_WAITFOR_LOCK
#define NOTIFY

template <typename T>
class SyncQueue {
public:
    SyncQueue() : mRunning(true) {
    }

    virtual ~SyncQueue() {
    }

    void Enqueue(const T& obj) {
        LOCK;
        mList.push_back(obj);
        NOTIFY;
        UNLOCK;
    }

    bool Dequeue(T& obj) {
        LOCK;
        while (mList.empty()) { //1
            if (!mRunning) {
                UNLOCK; //2
                return false;
            }
            UNLOCK_WAITFOR_LOCK;
        }
        obj = mList.front();
        mList.pop_front();
        UNLOCK;
        return true;
    }

    //3
    void Terminate() {
        mRunning = false;
        NOTIFY;
    }

protected:
    std::list<T> mList;
    bool mRunning;
};










1.不能超时返回。
2.注意这里要解锁。
3.很突兀的一段代码。
